package 面试真题;

public class L1 {
    private static int row ;
    private static int column;
    private static boolean ans;
    public static void main(String[] args) {
        int[][] ints = new int[3][3];
        ints[0] = new int[]{0,0,0};
        ints[1] = new int[]{0,1,0};
        ints[2] = new int[]{0,1,0};
        System.out.println(check(ints));

    }

    public static boolean check(int[][] values) {
        row = values.length;
        column = values[0].length;
        traceBack(values,0,0,new boolean[row][column]);
        return ans;
    }

    private static void traceBack(int[][] values, int i, int j, boolean[][] visited) {
        if(visited[i][j] || values[i][j]==1 ) return;
        if(i==row-1&&j==column-1) {
            ans = true;
            return;
        }
        visited[i][j] = true;
        if(i-1>=0) traceBack(values,i-1,j,visited);
        if(i+1<row) traceBack(values,i+1,j,visited);
        if(j-1>=0) traceBack(values,i,j-1,visited);
        if(j+1<column) traceBack(values,i,j+1,visited);
//        visited[i][j] = false;

    }


}
